
var url = require('url');

//事件池
var gGetLisiteners = {};
var gPostListeners = {};

var app = function(req, res) {
	var method = req.method.toLowerCase();
	var pathname = url.parse(req.url, true).pathname;
	console.log('=====', method)
	if (method == "get") {
		try {
			gGetLisiteners[pathname](req, res);
		} catch(err) {
			gGetLisiteners['/index'](req, res);
		}
	} else {
		try {
			gPostListeners[pathname](req, res);
		} catch(err) {
			gGetLisiteners['/index'](req, res);
		}
	}
	
}

app.get = function(string, callback) {
	gGetLisiteners[string] = callback;
	console.log("get = >", gGetLisiteners);
}

app.post = function(string, callback) {
	gPostListeners[string] = callback;
	console.log("post = >", gPostListeners);
}

module.exports = app;